﻿bob.ns.setNs('bob.code.module.tests', {

    TestModule: function () {

        this.test_ModuleObserver = function () {

            var mo = new bob.code.module.ModuleObserver();

            bob.assert.throwsError(function () { mo.setLoaded(); }, '0');
            bob.assert.throwsError(function () { mo.setLoaded('', arg); }, '0.1');

            var modName = 'mod01';
            var arg = 12;
            mo.setLoaded(modName, arg);

            bob.assert.throwsError(function () { mo.setLoaded(modName, arg); }, '3');

            var bLoaded = false;
            mo.whenLoaded(modName, function (arg2) {
                bLoaded = true;
                bob.assert.equals(arg, arg2, '4');
            });
            bob.assert.isTrue(bLoaded, '5');

            var modName = 'mod02';
            var arg = 'the arg';
            var bLoaded = false;

            mo.whenLoaded(modName, function (arg2) {
                bLoaded = true;
                bob.assert.equals(arg, arg2, '6');
            });
            bob.assert.isFalse(bLoaded, '7');

            mo.setLoaded(modName, arg);
            bob.assert.isTrue(bLoaded, '5');

            var modName = 'mod03';
            var arg = 103;
            var bLoaded1 = false;
            var bLoaded2 = false;
            var bLoaded3 = false;

            mo.whenLoaded(modName, function (arg2) {
                bLoaded1 = true;
                bob.assert.equals(arg, arg2, '8');
            });
            mo.whenLoaded(modName, function (arg2) {
                bLoaded2 = true;
                bob.assert.equals(arg, arg2, '9');
            });
            bob.assert.isFalse(bLoaded1, '10');
            bob.assert.isFalse(bLoaded2, '11');
            bob.assert.isFalse(bLoaded3, '12');

            mo.setLoaded(modName, arg);
            bob.assert.isTrue(bLoaded1, '13');
            bob.assert.isTrue(bLoaded2, '14');
            bob.assert.isFalse(bLoaded3, '15');

            mo.whenLoaded(modName, function (arg2) {
                bLoaded3 = true;
                bob.assert.equals(arg, arg2, '16');
            });
            bob.assert.isTrue(bLoaded3, '17');
        };

    }

});